#include <iostream>
using namespace std;

/*
	Rect  r4=9+r1+5+r2+6+r3-7; 
*/

class Rect
{
public:
	Rect(int _w=0,int _h=0)
	{
		w=_w;
		h=_h;
	}
	Rect operator+(int n)
	{
		cout<<"成员版本的加法重载，带int参数"<<endl;
		Rect temp;
		temp.w=n+w;
		temp.h=n+h;
		return temp;
	}
	Rect operator-(int n)
	{
		cout<<"成员版本的减法重载，带int参数"<<endl;
		Rect temp;
		temp.w=w-n;
		temp.h=h-n;
		return temp;
	}
	Rect operator+(Rect &other)
	{
		cout<<"成员版本的加法重载，带Rect参数"<<endl;
		Rect temp;
		temp.w=w+other.w;
		temp.h=h+other.h;
		return temp;
	}
	void show() const
	{
		cout<<"宽: "<<w<<"  高: "<<h<<endl;
	}
	friend Rect operator+(int n,Rect &other);
private:
	int w;
	int h;
};

Rect operator+(int n,Rect &other)
{
	cout<<"友元版本的加法重载"<<endl;
	Rect temp;
	temp.w=n+other.w;
	temp.h=n+other.h;
	return temp;
}



int main()
{
	Rect r1(10,5);
	Rect r2(25,17);
	Rect r3(40,22);
	Rect r4=9+r1+5+r2+6+r3-7; 
	r4.show();
}